package com.freeseed.model.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.freeseed.model.entity.CityDtl;
import com.freeseed.model.mapper.CityDtlMapper;
import com.freeseed.model.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allwayz
 * @since 2020-03-20
 */
@Slf4j
@RestController
@RequestMapping("cities")
public class CityDtlController {
    @Autowired
    private CityDtlMapper cityDtlMapper;

    @GetMapping
    public List<CityDtl> getCityDtlList(){
        List<CityDtl> cityDtlList = cityDtlMapper.selectList(new QueryWrapper<>());
        return cityDtlList;
    }

    @GetMapping("{Id}")
    public CityDtl getCityDtlById(@PathVariable int Id){
        CityDtl cityDtl = cityDtlMapper.selectById(Id);
        return cityDtl;
    }

    @PostMapping
    public CityDtl addCityDtl(CityDtl cityDtl){
        cityDtlMapper.insert(cityDtl);
        return cityDtl;
    }

    @PutMapping
    public CityDtl updateCityDtl(CityDtl cityDtl){
        cityDtlMapper.update(cityDtl,new UpdateWrapper<CityDtl>().eq("city_dtl_id",cityDtl.getCityDtlId()));
        return cityDtl;
    }

    @DeleteMapping("{Id}")
    public void deleteCityDtlById(@PathVariable int Id){
        cityDtlMapper.deleteById(Id);
    }
}
